/*
 * @FilePath: /flutter_cart/lib/pages/details_page/details_top_area.dart
 * @Author: Yongchao Wang
 * @Date: 2020-12-10 22:11:30
 * @LastEditors: Yongchao Wang
 * @LastEditTime: 2020-12-11 07:29:56
 */
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../provide/details_info.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class DetailTopArea extends StatelessWidget {
  const DetailTopArea({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Consumer<DetailsInfoProvide>(
      builder:
          (BuildContext context, DetailsInfoProvide detailsinfo, Widget child) {
        if (detailsinfo.goodInfo != null) {
          var goodsinfo = detailsinfo.goodInfo.data.goodInfo;
          return Container(
            color: Colors.white,
            child: Column(
              children: [
                _goodsImage(goodsinfo.image1),
                _goodsName(goodsinfo.goodsName),
                _goodsNum(goodsinfo.goodsSerialNumber),
                _goodsPrice(goodsinfo.presentPrice, goodsinfo.oriPrice)
              ],
            ),
          );
        } else {
          return Text('正在加载中');
        }
      },
    );
  }

  Widget _goodsImage(url) {
    return Image.network(
      url,
      width: ScreenUtil().setHeight(740),
    );
  }

  Widget _goodsName(name) {
    return Container(
      width: ScreenUtil().setWidth(720),
      padding: EdgeInsets.only(left: 15.0),
      child: Text(
        name,
        style: TextStyle(fontSize: ScreenUtil().setSp(30)),
      ),
    );
  }

  Widget _goodsNum(num) {
    return Container(
      width: ScreenUtil().setWidth(730),
      padding: EdgeInsets.only(left: 15.0),
      margin: EdgeInsets.only(top: 8.0),
      child: Text(
        '编号' + num,
        style: TextStyle(color: Colors.black12),
      ),
    );
  }

  //商品价格方法

  Widget _goodsPrice(presentPrice, oriPrice) {
    return Container(
      width: ScreenUtil().setWidth(730),
      padding: EdgeInsets.only(left: 15.0),
      margin: EdgeInsets.only(top: 8.0),
      child: Row(
        children: <Widget>[
          Text(
            '￥$presentPrice',
            style: TextStyle(
              color: Colors.pinkAccent,
              fontSize: ScreenUtil().setSp(40),
            ),
          ),
          Text(
            '市场价:￥$oriPrice',
            style: TextStyle(
                color: Colors.black26, decoration: TextDecoration.lineThrough),
          )
        ],
      ),
    );
  }
}
